//
//  CFMainViewController.swift
//  花菜微博
//
//  Created by 花菜ChrisCai on 2016/11/30.
//  Copyright © 2016年 花菜ChrisCai. All rights reserved.
//

import UIKit

class CFMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = UIColor.white
        // Do any additional setup after loading the view.
        setupChildViewControllers()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    }

extension CFMainViewController {
    fileprivate func setupChildViewControllers() {
        let tmp = [
            ["clsName" : "CFHomeViewController", "title" : "首页", "imageName" : "tabbar_home", "selectedImageName" : "tabbar_home_highlighted"],
            ["clsName" : "CFMessageViewController", "title" : "消息", "imageName" : "tabbar_message_center", "selectedImageName" : "tabbar_message_center_highlighted"],
            ["clsName" : "CFDiscoverViewController", "title" : "发现", "imageName" : "tabbar_discover", "selectedImageName" : "tabbar_discover_highlighted"],
            ["clsName" : "CFPofileViewController", "title" : "我的", "imageName" : "tabbar_profile", "selectedImageName" : "tabbar_profile_highlighted"],
        ]
        for dict in tmp {
            addChildViewController(controller(dict: dict))
        }
    }

    private func controller(dict : [String : String]) -> UIViewController {
        guard let clsName = dict["clsName"],
            let title = dict["title"],
            let imageName = dict["imageName"],
            let selectedImageName = dict["selectedImageName"],
            let cls = NSClassFromString(Bundle.main.nameSpace + clsName) as? UIViewController.Type
            else {
                return UIViewController()
        }
        let vc = cls.init()
        vc.title = title
        vc.tabBarItem.image = UIImage(named: imageName)
        vc.tabBarItem.selectedImage = UIImage(named: selectedImageName)
        return CFNavigationController(rootViewController: vc)
    }
    
}
